package auth

import (
	"basic-go/syntax/webook/internal/service/sms"
	"context"
	"github.com/golang-jwt/jwt/v5"
)

type AuthSmsService struct {
	sms sms.Service
	key []byte
}

type SmsClaim struct {
	jwt.RegisteredClaims
	tpl string
}

func (s *AuthSmsService) Send(ctx context.Context, tpl string, args []string, numbers ...string) error {
	var sc SmsClaim
	_, err := jwt.ParseWithClaims(tpl, sc, func(token *jwt.Token) (interface{}, error) {
		return s.key, nil
	})
	if err != nil {
		return err
	}
	return s.sms.Send(ctx, sc.tpl, args, numbers...)
}
